package com.example.springbootlocal.utils;


import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author X.I.O
 * @title: RequestUtils
 * @projectName springboot
 * @description: TODO
 * @date 2021/10/29 18:39
 */
public class Requestutils {

    /**
     * 获取当前会话中的HttpServletRequest
     *
     * @Title: getHttpServletRequest
     * @return: HttpServletRequest
     */
    public static HttpServletRequest getHttpServletRequest() {
        ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (sra != null) {
            return sra.getRequest();
        }
        return null;
    }


}
